package com.neo.rabbitmq.two;

import com.neo.rabbitmq.utils.RabbitMqUtil;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @ClassName: Worker01
 * @Title: rabbitmq-demo
 * @Package: com.neo.rabbitmq.two
 * @Description: 工作线程（相当于之前消费者）
 * @Author: Kisen
 * @Date: 2021/9/2 23:10
 */
public class Worker01 {
    // 队列的名称
    public static final String QUEUE_NAME = "hello";

    // 接收消息
    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtil.getChannel();

        // 消息的接收
        DeliverCallback deliverCallback = (consumerTag, message) -> System.out.println("接收到的消息：" + new String(message.getBody()));
        // 消息接收被取消时，执行下面的内容
        CancelCallback cancelCallback = consumerTag -> System.out.println("消费被取消消费接口回调逻辑");
        // 消费者消费消息
        System.out.println("C2等待接收消息......");
        channel.basicConsume(QUEUE_NAME, true, deliverCallback, cancelCallback);
    }
}
